using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The UserAccountTableManager class is responsible for managing BO.UserAccountTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class UserAccountTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all UserAccountTable objects in the database.
        /// </summary>
        /// <returns>A list with all UserAccountTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static UserAccountTableList GetList()
        {
            return UserAccountTableDB.GetList();
        }

        /// <summary>
        /// Gets a single UserAccountTable from the database without its data.
        /// </summary>
        /// <param name="userAccountKey">The UserAccountKey of the UserAccountTable in the database.</param>
        /// <returns>A UserAccountTable object when the UserAccountKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static UserAccountTable GetItem(int userAccountKey)
        {
            return GetItem(userAccountKey, false);
        }

        /// <summary>
        /// Gets a single UserAccountTable from the database.
        /// </summary>
        /// <param name="userAccountKey">The UserAccountKey of the UserAccountTable in the database.</param>
        /// <param name="getUserAccountTableRecords">Determines whether to load all associated UserAccountTable records as well.</param>
        /// <returns>
        /// A UserAccountTable object when the UserAccountKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static UserAccountTable GetItem(int userAccountKey, bool getUserAccountTableRecords)
        {
            UserAccountTable myUserAccountTable = UserAccountTableDB.GetItem(userAccountKey);
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.classRoomLocationTables = ClassRoomLocationTableDB.GetListBySupervisorUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.familyMemberAddressTables = FamilyMemberAddressTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.familyMemberContactTables = FamilyMemberContactTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.guardianAddressTables = GuardianAddressTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.guardianContactTables = GuardianContactTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.guardianProfileTables = GuardianProfileTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.studentContactTables = StudentContactTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.studentProfileTables = StudentProfileTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.teacherAddressTables = TeacherAddressTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.teacherContactTables = TeacherContactTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.teacherProfileTables = TeacherProfileTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.userAddressTables = UserAddressTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.userContactTables = UserContactTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            //if (myUserAccountTable != null && getUserAccountTableRecords)
            //{
            //    myUserAccountTable.userProfileTables = UserProfileTableDB.GetListByUserAccountKey(userAccountKey);
            //}
            return myUserAccountTable;
        }

        /// <summary>
        /// Saves a UserAccountTable in the database.
        /// </summary>
        /// <param name="myUserAccountTable">The UserAccountTable instance to save.</param>
        /// <returns>The new UserAccountKey if the UserAccountTable is new in the database or the existing UserAccountKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(UserAccountTable myUserAccountTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int userAccountTableUserAccountKey = UserAccountTableDB.Save(myUserAccountTable);

                //foreach (ClassRoomLocationTable myClassRoomLocationTable in myUserAccountTable.classRoomLocationTables)
                //{
                //    myClassRoomLocationTable.UserAccountKey = userAccountTableUserAccountKey;
                //    ClassRoomLocationTableDB.Save(myClassRoomLocationTable);
                //}
                //foreach (FamilyMemberAddressTable myFamilyMemberAddressTable in myUserAccountTable.familyMemberAddressTables)
                //{
                //    myFamilyMemberAddressTable.UserAccountKey = userAccountTableUserAccountKey;
                //    FamilyMemberAddressTableDB.Save(myFamilyMemberAddressTable);
                //}
                //foreach (FamilyMemberContactTable myFamilyMemberContactTable in myUserAccountTable.familyMemberContactTables)
                //{
                //    myFamilyMemberContactTable.UserAccountKey = userAccountTableUserAccountKey;
                //    FamilyMemberContactTableDB.Save(myFamilyMemberContactTable);
                //}
                //foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myUserAccountTable.familyMemberProfileTables)
                //{
                //    myFamilyMemberProfileTable.UserAccountKey = userAccountTableUserAccountKey;
                //    FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
                //}
                //foreach (GuardianAddressTable myGuardianAddressTable in myUserAccountTable.guardianAddressTables)
                //{
                //    myGuardianAddressTable.UserAccountKey = userAccountTableUserAccountKey;
                //    GuardianAddressTableDB.Save(myGuardianAddressTable);
                //}
                //foreach (GuardianContactTable myGuardianContactTable in myUserAccountTable.guardianContactTables)
                //{
                //    myGuardianContactTable.UserAccountKey = userAccountTableUserAccountKey;
                //    GuardianContactTableDB.Save(myGuardianContactTable);
                //}
                //foreach (GuardianProfileTable myGuardianProfileTable in myUserAccountTable.guardianProfileTables)
                //{
                //    myGuardianProfileTable.UserAccountKey = userAccountTableUserAccountKey;
                //    GuardianProfileTableDB.Save(myGuardianProfileTable);
                //}
                //foreach (StudentContactTable myStudentContactTable in myUserAccountTable.studentContactTables)
                //{
                //    myStudentContactTable.UserAccountKey = userAccountTableUserAccountKey;
                //    StudentContactTableDB.Save(myStudentContactTable);
                //}
                //foreach (StudentProfileTable myStudentProfileTable in myUserAccountTable.studentProfileTables)
                //{
                //    myStudentProfileTable.UserAccountKey = userAccountTableUserAccountKey;
                //    StudentProfileTableDB.Save(myStudentProfileTable);
                //}
                //foreach (TeacherAddressTable myTeacherAddressTable in myUserAccountTable.teacherAddressTables)
                //{
                //    myTeacherAddressTable.UserAccountKey = userAccountTableUserAccountKey;
                //    TeacherAddressTableDB.Save(myTeacherAddressTable);
                //}
                //foreach (TeacherContactTable myTeacherContactTable in myUserAccountTable.teacherContactTables)
                //{
                //    myTeacherContactTable.UserAccountKey = userAccountTableUserAccountKey;
                //    TeacherContactTableDB.Save(myTeacherContactTable);
                //}
                //foreach (TeacherProfileTable myTeacherProfileTable in myUserAccountTable.teacherProfileTables)
                //{
                //    myTeacherProfileTable.UserAccountKey = userAccountTableUserAccountKey;
                //    TeacherProfileTableDB.Save(myTeacherProfileTable);
                //}
                //foreach (UserAddressTable myUserAddressTable in myUserAccountTable.userAddressTables)
                //{
                //    myUserAddressTable.UserAccountKey = userAccountTableUserAccountKey;
                //    UserAddressTableDB.Save(myUserAddressTable);
                //}
                //foreach (UserContactTable myUserContactTable in myUserAccountTable.userContactTables)
                //{
                //    myUserContactTable.UserAccountKey = userAccountTableUserAccountKey;
                //    UserContactTableDB.Save(myUserContactTable);
                //}
                //foreach (UserProfileTable myUserProfileTable in myUserAccountTable.userProfileTables)
                //{
                //    myUserProfileTable.UserAccountKey = userAccountTableUserAccountKey;
                //    UserProfileTableDB.Save(myUserProfileTable);
                //}

                //  Assign the UserAccountTable its new (or existing UserAccountKey).
                myUserAccountTable.UserAccountKey = userAccountTableUserAccountKey;

                myTransactionScope.Complete();

                return userAccountTableUserAccountKey;
            }
        }

        /// <summary>
        /// Deletes a UserAccountTable from the database.
        /// </summary>
        /// <param name="myUserAccountTable">The UserAccountTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(UserAccountTable myUserAccountTable)
        {
            return UserAccountTableDB.Delete(myUserAccountTable.UserAccountKey);
        }

        #endregion

    }

}
